# 电子票盖章

# from PIL import Image, ImageFont, ImageDraw
# #打开图片
# im = Image.open("./1233.jpg").convert('RGBA')
# #新建一个空白图片,尺寸与打开图片一样
# txt=Image.new('RGBA', im.size, (0,0,0,0))
# #设置字体
# fnt=ImageFont.truetype("c:/Windows/Fonts/Tahoma.ttf", 40)
# #操作新建的空白图片>>将新建的图片添入画板
# d=ImageDraw.Draw(txt)
# #在新建的图片上添加字体
# d.text((txt.size[0]-115,txt.size[1]-80), "九点半", font=fnt, fill=(255,255,255,255))
# #合并两个图片
# out=Image.alpha_composite(im, txt)
# out.show()

from PIL import Image
im = Image.open("img/OCR.png")
mark=Image.open("./m1.png")
layer=Image.new('RGBA', im.size, (100, 0, 0, 0))
layer.paste(mark, (im.size[0]-60, im.size[1]-200))    # (左右, 上下)
out=Image.composite(layer, im, layer)
out.save(r'777.png')
out.show()



# #coding:utf-8
# import cv2
# import numpy as np
#
# #加载图片
# image = cv2.imread('./890.jpg')
# #统一处理图片大小
# img_w = 650 if image.shape[1] > 600 else 400
# image = cv2.resize(image, (img_w,int(img_w*image.shape[0]/image.shape[1])), interpolation=cv2.IMREAD_COLOR)
# impng=cv2.cvtColor(image.copy(), cv2.COLOR_RGB2RGBA)
# # image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGR)
# #image = cv2.imread('img\\public-2004-16-a7912dbd-72b0-4d96-9d65-70abc21940d5.png')
# hue_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# low_range = np.array([130, 43, 46])
# high_range = np.array([180, 255, 255])
# th = cv2.inRange(hue_image, low_range, high_range)
# element = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))
# th = cv2.dilate(th, element)
# index1 = th == 255
# img1 = np.zeros(impng.shape, np.uint8)
# img1[:,:,:] = (255, 255, 255,0)
# img1[index1] = impng[index1]  # (0,0,255)
#
# # img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
# # 创建四通道图片
# #img1=topng(img1)
# #img1 = cv2.cvtColor(img1, cv2.COLOR_RGB2RGBA)
# cv2.imwrite('m1.png', img1)
# cv2.imshow('1', img1)
# #cv2.waitKey()
# # cv2.imwrite("img1.png", img1)
# low_range = np.array([0, 43, 46])
# high_range = np.array([9, 255, 255])
# th = cv2.inRange(hue_image, low_range, high_range)
# element = cv2.getStructuringElement(cv2.MORPH_RECT, (1, 1))
# th = cv2.dilate(th, element)
# index1 = th == 255
# img2 = np.zeros(impng.shape, np.uint8)
# img2[:,:,:] = (255, 255, 255,0)
# img2[index1] = impng[index1]
# cv2.imshow('2', img2)
# cv2.imwrite('m2.png', img2)
#
# imgreal=cv2.add(img2,img1)
# cv2.imwrite('m222.png', imgreal)
# #cv2.waitKey()
# #img31 = cv2.cvtColor(img31, cv2.COLOR_BGR2RGB)
# white_px = np.asarray([255, 255, 255,255])
# #black_px = np.asarray([0, 0, 0, 255])
# (row, col, _) = imgreal.shape
# for r in range(row):
#     for c in range(col):
#         px = imgreal[r][c]
#         if all(px == white_px):
#             imgreal[r][c] = impng[r][c]
#
# #扩充图片防止截取部分
# img4png=cv2.copyMakeBorder(imgreal, 50, 50, 50, 50,cv2.BORDER_CONSTANT, value=[255, 255, 255,0])
# img2gray = cv2.cvtColor(img4png, cv2.COLOR_RGBA2GRAY)
# retval, grayfirst = cv2.threshold(img2gray, 254, 255, cv2.THRESH_BINARY_INV)
#
# # 再次膨胀，轮廓查找
# # img6 = cv2.GaussianBlur(grayfirst, (25, 5), 0, 0)
# element = cv2.getStructuringElement(cv2.MORPH_RECT, (22, 22))
# img6 = cv2.dilate(grayfirst, element)
# #cv2.imshow('img4', img6)
#
# c_canny_img = cv2.Canny(img6, 10, 10)
#
# contours, hierarchy = cv2.findContours(c_canny_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# areas = []
# for i, cnt in enumerate(contours):
#     rect = cv2.minAreaRect(cnt)
#     x, y, w, h = cv2.boundingRect(cnt)
#     area = w * h
#     ars = [area, i]
#     areas.append(ars)
# areas = sorted(areas, reverse=True)
# print(areas)
# maxares = areas[:1]
#
# x, y, w, h = cv2.boundingRect(contours[maxares[0][1]])
# temp = img4png[y:(y + h), x:(x + w)]
# #高小于宽
# print(temp.shape)
# # if temp.shape[0]